import time

from selenium.webdriver.common.by import By

from Pages import BasePage

class adminHotelDetailPage(BasePage.Action):
    def __init__(self):
        self.acceptBook_xpath = (By.XPATH, "//button[contains(@class,'el-button--primary')]/span[contains(text(),'预订确认')]")
        self.sure_xpath = (By.XPATH, "/html/body/div[2]/div/div[3]/button[2]/span")
        #退改处理按钮
        self.refundChange_xpath = (By.XPATH, "//button[contains(@class,'el-button--primary')]/span[contains(text(),'退改处理')]")
        #退改处理--申请单状态为待处理的【操作】按钮
        self.operateButton_xpath = (By.XPATH, "//div[text()='待处理']/../..//span[text()='操作']")
        self.changeCheck_xpath = (By.XPATH, "//ul/li[contains(text(),'改期审核')]")
        self.refundCheck_xpath = (By.XPATH, "//ul/li[contains(text(),'退房审核')]")
        #同意
        self.agreeRadio_xpath = (By.XPATH, "//span[@class='el-radio__label'][text()='同意']")
        #改签处理按钮
        self.agreeChangeSure_xpath = (By.XPATH, "//div[not (contains(@style,'display: none;'))]/div/div/span/button/span[text()='确定']")
        #退订处理按钮
        self.agreeRefundSure_xpath = (By.XPATH, "//div[not (contains(@style,'display: none;'))]/div/div/span/button/span[text()='确定']")

    def acceptBook(self):
        time.sleep(2)
        self.smart_click(*self.acceptBook_xpath)
        time.sleep(2)
        self.smart_click(*self.sure_xpath)
        time.sleep(2)

    def acceptChange(self):
        time.sleep(2)
        if self.find_element(*self.refundChange_xpath):
            self.smart_click(*self.refundChange_xpath)
            time.sleep(1)
            self.smart_click(*self.operateButton_xpath)
            time.sleep(1)
            self.smart_click(*self.changeCheck_xpath)
            time.sleep(1)
            self.smart_click(*self.agreeRadio_xpath)
            time.sleep(2)
            self.scroll_into_view(self.find_element(*self.agreeChangeSure_xpath))
            time.sleep(1)
            self.find_element(*self.agreeChangeSure_xpath).click()
            time.sleep(5)
            print("处理确认改签")
        else:
            print("订单无需处理")
            return

    def acceptRefund(self):
        time.sleep(2)
        if self.find_element(*self.refundChange_xpath):
            self.smart_click(*self.refundChange_xpath)
            time.sleep(1)
            self.smart_click(*self.operateButton_xpath)
            time.sleep(1)
            self.smart_click(*self.refundCheck_xpath)
            time.sleep(1)
            self.smart_click(*self.agreeRadio_xpath)
            time.sleep(2)
            self.scroll_into_view(self.find_element(*self.agreeRefundSure_xpath))
            time.sleep(2)
            self.smart_click(*self.agreeRefundSure_xpath)
            time.sleep(5)
            print("处理确认退订")
        else:
            print("订单无需处理")
            return


